package net.keebook.webapp.entity;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;

import net.keebook.webapp.util.ExposableId;


@Entity
public class PasswordItem implements Serializable, ExposableId {
	private static final long serialVersionUID = 1L;
	
	@Id @GeneratedValue(strategy=GenerationType.IDENTITY)
	private Long id;
	private String title;
	private String username;
	private String password;
	private String url;
	@Column(columnDefinition="TEXT")
	private String notes;
	@ManyToOne(fetch=FetchType.EAGER)
	private KeeBook keeBook;
	@Column(unique=true)
	private String exposableId;
	private Date creationTime;
	private Date lastModification;
	private Boolean favored = false;
	@ManyToOne(fetch=FetchType.EAGER)
	private ItemGroup group;
	
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getUrl() {
		return url;
	}
	public void setUrl(String url) {
		this.url = url;
	}
	public String getNotes() {
		return notes;
	}
	public void setNotes(String notes) {
		this.notes = notes;
	}
	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
	public Date getCreationTime() {
		return creationTime;
	}
	public void setCreationTime(Date creationTime) {
		this.creationTime = creationTime;
	}
	public Date getLastModification() {
		return lastModification;
	}
	public void setLastModification(Date lastModification) {
		this.lastModification = lastModification;
	}
	public ItemGroup getGroup() {
		return group;
	}
	public void setGroup(ItemGroup group) {
		this.group = group;
	}
	public String getExposableId() {
		return exposableId;
	}
	public void setExposableId(String exposableId) {
		this.exposableId = exposableId;
	}
	public KeeBook getKeeBook() {
		return keeBook;
	}
	public void setKeeBook(KeeBook keeBook) {
		this.keeBook = keeBook;
	}
	
	@Override
	public PasswordItem clone() throws CloneNotSupportedException {
		PasswordItem item = new PasswordItem();
		item.setCreationTime(getCreationTime());
		item.setExposableId(getExposableId());
		item.setGroup(getGroup());
		item.setId(getId());
		item.setKeeBook(getKeeBook());
		item.setLastModification(getLastModification());
		item.setNotes(getNotes());
		item.setPassword(getPassword());
		item.setTitle(getTitle());
		item.setUrl(getUrl());
		item.setUsername(getUsername());
		return item;
	}
	public Boolean getFavored() {
		return favored;
	}
	public void setFavored(Boolean favored) {
		this.favored = favored;
	}
}
